var id = '',
      keyword = "";
    if (GetQueryString("keyword")) {
      keyword = GetQueryString("keyword")
    }
    if (GetQueryString("id")) {
      id = GetQueryString("id")
    }

    $(".news-filter-nav-bar").click(function () {
      $(this).siblings().toggle()
    })

    $(document).delegate(".news-filter-item", "click", function () {
      id = ($(this).data("id"))
      getArticlleData()
    })


    // 资讯搜索
    $(".news-search-content input").bind('keydown', function (event) {
      var event = window.event || arguments.callee.caller.arguments[0];
      if (event.keyCode == 13) {
        keyword = $(".news-search-content input").val()
        if(keyword==''){
          alert("请填写搜索词!")
          return;
        }
        getArticlleData()
      }
    });

    $(".news-search-content div").click(function () {
      keyword = $(".news-search-content input").val()
      if(keyword==''){
          alert("请填写搜索词!")
          return;
        }
      getArticlleData()
    })

    // 获取左侧分类的数据
    function getClassData() {
      $.ajax({
        url: `${HOST}/index/article/cate`,
        type: "post",
        success: (res) => {
          if (res.success == 1) {
            var data = res.data,
              str = "";
            for (var i = 0; i < data.length; i++) {
              str += `<div class="news-filter-item" data-id="${data[i].id}">${data[i].name}</div>`
            }
            // console.log(str)

            $(".news-filter-items-box").html(str);
          }

        }
      })
    }

    // 获取文章的数据(正常load)
    function getArticlleData() {
      $.ajax({
        url: `${HOST}/index/article/article`,
        type: "post",
        data: {
          cate: id || '',
          search: keyword || ''
        },
        success: (res) => {
          console.log(res)
          if (res.success == 1) {
            var data = res.data,
              str = "";
            for (var i = 0; i < data.length; i++) {
              str += `<a href="./news-details.html?id=${data[i].id}">
                    <div class="news-item-box">
                      <div class="news-lit-item">
                        <img src="${HOST+data[i].thumb}" alt="">
                        <section class="news-item-content">
                          <div class="news-item-content-title hide-txt">${data[i].title}</div>
                          <div class="news-item-content-pre hide-txts">${data[i].description}</div>
                        </section>
                      </div>
                    </div>
                  </a>`
            }
            $(".new-list-box").html(str);
          } else {
            $(".new-list-box").html("没有搜索到,换个词或者分类吧");
          }

        }
      })
    }
    getArticlleData()
    getClassData()